<?php

function menu()
{
  $MENU = array();
	$menu .= "<br/>"."\n";
	$menu .="<b>".__('Baza Klientów')."</b>";
  array_push($MENU, array(
      "title"=>__('Baza Klientów'),
      "items"=>array(
          array("title"=>__("Wyszukiwarka Firm i Klientów"),"tag"=>"candAdd","link"=>"index.php?action=clients","level"=>0),
          array("title"=>__("Moje Firmy"),"tag"=>"candAdd","link"=>"index.php?action=companys&site=mycompanys","level"=>0),
          array("title"=>__("Moi Klienci"),"tag"=>"candAdd","link"=>"index.php?action=clients&site=myclients","level"=>0),
          array("title"=>__("Firmy"),"tag"=>"candAdd","link"=>"index.php?action=companys")
        )
      ));
  if( in_array(User_Session::getUserRights(), array(1,2,3))) {
      array_push($MENU[0]['items'],array("title"=>__("Klienci"),"tag"=>"candAdd","link"=>"index.php?action=contacts&site=search"));
  }
  $menu .= "<br/><br/>"."\n";
  //tymczasowo tutaj zostaje, po przeniesieniu wszystkich modulow zrobic z tym porzadek za pomoca order w modules

	$menu .= Application::linkMenuButton(__("Wyszukiwarka Firm i Klientów"), "candAdd", "index.php?action=clients")."<br/>"."\n";
	$menu .= Application::linkMenuButton(__("Moje Firmy"), "candAdd", "index.php?action=companys&site=mycompanys")."<br/>"."\n";
	$menu .= Application::linkMenuButton(__("Moi Klienci"), "candAdd", "index.php?action=clients&site=myclients")."<br/>"."\n";
  $menu .= "<br>"."\n";
	$menu .= Application::linkMenuButton(__("Firmy"), "candAdd", "index.php?action=companys")."<br/>"."\n";

	if( isset($_SESSION['user_rights']) && $_SESSION['user_rights'] == 3 ) {
    //$menu .= Application::linkMenuButton("Klienci", "candAdd", "index.php?action=contacts&site=results&user=&firma=&dzial=0&oferta=0&keyword=&data_od=&data_do=")."<br/>"."\n";
    $menu .= Application::linkMenuButton(__("Klienci"), "candAdd", "index.php?action=contacts&site=search")."<br/>"."\n";
  }
  else if( User_Session::getUserRights() == 2 ) {
    $menu .= Application::linkMenuButton(__("Klienci"), "candAdd", "index.php?action=contacts&site=search")."<br/>"."\n";
  }

  $MENU += Module::getMenus();
  
  $menu .= "<script>\$MENU = ".json_encode($MENU)."</script>";

  foreach($MENU as $module => $MOD_MENU) {

    if (empty($MOD_MENU)) {
      continue;
    }

    if ($MOD_MENU['title']) {
			$menu .= "<br><b>".__($MOD_MENU['title']).":</b><br/><br/>"."\n";
    }

    foreach($MOD_MENU['items'] as $MOD_MENU_ITEM) {
			$menu .= Application::linkMenuButton(__($MOD_MENU_ITEM['title']), $MOD_MENU_ITEM['tag'], $MOD_MENU_ITEM['link'])."<br/>"."\n";
    }
  }
  
  $menu .= "<script> Application.initMenu(\$MENU)</script>";
  return $menu;
}


